package com.weigongbao.weigongbao;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
public class ShowImageActivity extends Activity {

    private ArrayList<String> list;
    private TextView page;
    private int positions;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show_activity);
        init();
    }

    private void init() {
        getData();
        page = (TextView) findViewById(R.id.show_tv);
        setPager(positions + 1);
        ViewPager mViewPager = (ViewPager) findViewById(R.id.show_vp);
        mViewPager.setAdapter(new MyPagerAdapter(list,this));
        mViewPager.setCurrentItem(positions);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                setPager(position + 1);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    private void setPager(int cpage){
        page.setText(cpage + "/" + list.size());
    }

    private void getData(){
        Intent intent = getIntent();
        list = intent.getStringArrayListExtra("list");
        positions = intent.getIntExtra("position",1);
    }

    public void exit(View view) {
//        Intent intent = new Intent();
        finish();
    }
}
